/*
 * Copyrights (C) 2008 HarbourNetowrks Co., Ltd.
 * LianHaidong <lianhaidong@gmail.com>
 */

#ifndef __HASH_H
#define __HASH_H

#include <inttypes.h>

/*
 * hash function --- can produce a digital value from the key
 */
typedef int (*hash_func_t)(void *key);

/*
 * key comparation function  
 */
typedef int (*key_compare_t)(void *key1, void *key2);

struct hash_node {
	void *key;
	void *data;
	struct hash_node *next;
};

struct hash_list {
	hash_func_t func;
	key_compare_t comp;
	uint32_t index_count;
	uint32_t node_count;
#if __GUNC__ <= 2
	struct hash_node *node[0];
#else
	struct hash_node *node[];
#endif
};


struct hash_list *hash_create(hash_func_t func, key_compare_t comp, uint32_t index_count);

int hash_delete(struct hash_list *hl);

int hash_list_insert(struct hash_list *hl, void *data, void *key);

void *hash_list_delete(struct hash_list *hl, void *key);

void *hash_list_peer(struct hash_list *hl, void *key);

#endif	/* __HASH_H */
